package com.kindnesslibrary.network.retrofit;

import com.kindnesslibrary.network.retrofit.invocation.MethodProxyFactory;

/**
 * 使用retrofit管理接口
 */
public class RetrofitManager {

    private Object apiService;

    private static class RetrofitManagerHolder {
        static final RetrofitManager INSTANCE = new RetrofitManager();
    }

    /**
     * private的构造函数用于避免外界直接使用new来实例化对象
     */
    private RetrofitManager() {

    }

    public static RetrofitManager getInstance() {
        return RetrofitManagerHolder.INSTANCE;
    }

    public <T> T getApiService(Class<T> apiService){
        if(this.apiService == null){
            this.apiService = MethodProxyFactory.newInstance(apiService);
        }
        return (T) this.apiService;
    }

}
